package com.shengzai

import scala.io.Source
// 计算班级人数
object Code37Example01{
  def main(args: Array[String]): Unit = {

    val fileList: List[String] = Source.fromFile("hadoop_code/src/data/students.txt").getLines().toList
    fileList.foreach(println)
    fileList.map(
      (value :String) =>{
        val stuSplit: Array[String] = value.split(",")
        new studentInfo(stuSplit(0),stuSplit(1),stuSplit(2).toInt,stuSplit(3),stuSplit(4))
      }
    ).groupBy(
      (value:studentInfo) =>{
        value.clazz
      }
    ).map(
      (kv:(String,List[studentInfo])) =>{
        (kv._1 ,kv._2.length)
      }
    ).foreach(println)


  }
}
case class studentInfo(id:String,name:String,age:Int,sex:String,clazz:String)
